const webpack = require('webpack')
const path = require('path')
//导入模拟数据
const appData = require('./data.json')
// const appData = require('http://120.78.171.194/JsonData/data.json')
const seller = appData.seller;
const goods = appData.goods;
const ratings = appData.ratings;

//路径alias别名函数
function resolve(dir) {
  return path.join(__dirname, dir);
}

module.exports = {
  css: {
    loaderOptions: {
      stylus: {
        'resolve url': true,
        'import': [
          './src/theme'
        ]
      }
    }
  },

  pluginOptions: {
    'cube-ui': {
      postCompile: true,
      theme: true
    }
  },

  // webpack-dev-server 相关配置
  devServer: {
    before: function(app) {
      app.get('/api/seller', function(req, res) {
        res.json({ 
          errno: 0,
          data: seller
         })
      })
      app.get('/api/goods', function(req, res) {
        res.json({ 
          errno: 0,
          data: goods
         })
      })
      app.get('/api/ratings', function(req, res) {
        res.json({ 
          errno: 0,
          data: ratings
         })
      })
    }
  },

  //webpack配置  see:  https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
  chainWebpack: (config) => {
    //在vue cli3中配置webpack目录别名alias的方式
    config.resolve.alias
      .set('components',resolve('src/components'))
      .set('common',resolve('src/common'))
      .set('api',resolve('src/api'))

    //  //base64相关代码
    // config.module
    //   .rule('images')
    //     .test(/\.(png|jpe?g|gif|webp)(\?.*)?$/)
    //     .use('url-loader')
    //     .loader('url-loader')
    //     .tap(options =>
    //       merge(options, {
    //         limit: 10000,
    //       })
    //     )
    config.plugin('context')
      .use(webpack.ContextReplacementPlugin,
        [/moment[/\\]locale$/, /zh-cn/])
  },
  baseUrl: '', // 注意：项目打包上线时，启用该行，开发时，注释掉该行
  // 第三方插件配置
  pluginOptions: {   },

  lintOnSave: undefined,
  publicPath: undefined,
  outputDir: undefined,
  assetsDir: undefined,
  runtimeCompiler: undefined,
  productionSourceMap: undefined,
  parallel: undefined
}
